// app.js
const updateManager = wx.getUpdateManager()
const app = getApp();
updateManager.onCheckForUpdate(function (res) {
  // 请求完新版本信息的回调
})
updateManager.onUpdateReady(function () {
  updateManager.applyUpdate()

})

updateManager.onUpdateFailed(function () {
  // 新版本下载失败
})
App({
  onLaunch: function () {
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    this.globalData.sysinfo = wx.getSystemInfoSync()
    var that = this;
    //获取用户本地是否是第一次进入新版本
    var versions = wx.getStorageSync('versions');
    console.log('versions:' + versions);
    //判断是不是需要授权
    if (versions == '1'){
      // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
      wx.getUserInfo({
        success: function (res) {
          that.globalData.userInfo = res.userInfo
          console.log(that.globalData.userInfo)
        },
        fail: function () {
        }
      })
    }else{
    }
    // 获取顶部栏信息
    wx.getSystemInfo({
      success: res => {
        //导航高度
        this.globalData.navHeight = res.statusBarHeight + 46;
        that.globalData.statusBarHeight = res.statusBarHeight*1+46*1
        that.globalData.statusBarHeight1 = res.statusBarHeight
        console.log(res.statusBarHeight, 'statusBarHeight')
      }, fail(err) {
        console.log(err);
      }
    })
  },
  globalData: {
    qians_1:'',
    img_id2:"",
    qians_2:'',
    qs_ht:"",
    type11:"",
    corpid:"",
    sm_qy:"",
    sm_rz:"",
    openid:"",
    sc:"",
    sc_ts:"",
    userid:"",
    mr_url:"",
    fq_sjid:"",
    fq_sjid1:"",
    fq_sjid2:"",
    img_id:"",
    img_id1:"",
    gl_id:"",
    num:"",
    sf_zt:"",
    sx_dm:"",
    postData:"",
    gt_s:"",
    ids:"",
    img_url:"",
    url_l: 'https://shy.xihenet.net/',
    userInfo: null,
    navHeight: 0,
    dd_lxq:'',
    appid: "",
    shuzs:1,
    status:"",
    state_lp:"",
    qx_id:"",
    uid:"",
    cx_xd:"",
    deji:"",
    gt_kp1:"",
    dz:"",
    corpid:"",
    dj_zt:"",
    tx:"",
    qe_id:"",
    j_id:"",
    hy_qid:"",
    fl_id:"",
    ttou_id:"",
    ttou_idc1:"",
    kp_rid:"",
    q_name1:"",
    ttou_name:"",
    lei_state:"",
    kp_idd1:"",
    r_namee1:"",
    d_id:"",
    gz_xz:"",
    fl_idd1:"",
    gs_namekp_f:"",
  screenWidth:wx.getSystemInfoSync().screenWidth,
  screenHeight:wx.getSystemInfoSync().screenHeight,
},

getModel: function () { //获取手机型号
  return this.globalData.sysinfo["model"]
},
getVersion: function () { //获取微信版本号
  return this.globalData.sysinfo["version"]
},
getSystem: function () { //获取操作系统版本
  return this.globalData.sysinfo["system"]
},
getPlatform: function () { //获取客户端平台
  return this.globalData.sysinfo["platform"]
},
getSDKVersion: function () { //获取客户端基础库版本
  return this.globalData.sysinfo["SDKVersion"]
},
BLEInformation:{
  platform: "",
  deviceId:"",
  writeCharaterId: "",    
  writeServiceId: "",
  notifyCharaterId: "",
  notifyServiceId: "",
  readCharaterId: "",
  readServiceId: "",
},
  getLocationInfo: function (cb) {
    var that = this;
    if (this.globalData.locationInfo) {
      cb(this.globalData.locationInfo)
    } else {
      wx.getLocation({
        type: 'gcj02', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
        success: function (res) {
          that.globalData.locationInfo = res;
          cb(that.globalData.locationInfo)
        },
        fail: function () {
          // fail
        },
        complete: function () {
          // complete
        }
      })
    }
  },
  util: require('utils/util.js'),

})


